from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QHBoxLayout, QWidget
import sys

class QuitApp(QMainWindow):

    def __init__(self):
        super(QuitApp, self).__init__()
        self.resize(500, 500)
        self.setWindowTitle("退出应用程序")

        # 关闭应用程序按钮
        self.btn1 = QPushButton("关闭应用程序")
        self.btn1.clicked.connect(self.close_app)

        layout = QHBoxLayout()
        layout.addWidget(self.btn1)

        mainFrame = QWidget()
        mainFrame.setLayout(layout)

        self.setCentralWidget(mainFrame)


    def close_app(self):
        print(self.sender().text()+"被点击了")
        app = QApplication.instance()
        app.quit()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QuitApp()
    main.show()
    sys.exit(app.exec_())

